package com.ruoyi.web.controller.laiqianba.source;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.channel.enums.ChannelTypeEnum;
import com.ruoyi.channel.enums.PageTypeEnum;
import com.ruoyi.channel.service.IChannelBaseInfoService;
import com.ruoyi.laiqianba.enums.BaseTypeInfoEnum;
import com.ruoyi.laiqianba.enums.ChargeTypeEnum;
import com.ruoyi.laiqianba.enums.InfoTypeEnum;
import com.ruoyi.laiqianba.enums.PostInfoEnum;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SourceBaseInfo;
import com.ruoyi.source.service.ISourceBaseInfoService;
import com.ruoyi.web.wrapper.SourceBaseInfoWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线索基本信息Controller
 * 
 * @author ruoyi
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/source/baseInfo")
public class SourceBaseInfoController extends BaseController
{
    @Autowired
    private ISourceBaseInfoService sourceBaseInfoService;
    @Autowired
    IChannelBaseInfoService  channelBaseInfoService;

    /**
     * 查询线索基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('source:baseInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SourceBaseInfo sourceBaseInfo)
    {
        startPage();
        List<Map<String, Object>> list = sourceBaseInfoService.selectSourceBaseInfoMapList(sourceBaseInfo);
        list = new SourceBaseInfoWrapper(list).wrap();
        return getDataTable(list);
    }


    /**
     *
     * /source/baseInfo/extData
     */
    @GetMapping("/extData")
    public AjaxResult extData()
    {
        JSONObject returnData = new JSONObject();
        returnData.put("channelNameList", channelBaseInfoService.getChannelNameList());
        returnData.put("sourceList", InfoTypeEnum.getMapList());
        return AjaxResult.success(returnData);
    }

    /**
     * 导出线索基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('source:baseInfo:export')")
    @Log(title = "线索基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SourceBaseInfo sourceBaseInfo)
    {
        List<SourceBaseInfo> list = sourceBaseInfoService.selectSourceBaseInfoList(sourceBaseInfo);
        ExcelUtil<SourceBaseInfo> util = new ExcelUtil<SourceBaseInfo>(SourceBaseInfo.class);
        util.exportExcel(response, list, "线索基本信息数据");
    }

    /**
     * 获取线索基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('source:baseInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sourceBaseInfoService.selectSourceBaseInfoById(id));
    }

    /**
     * 新增线索基本信息
     */
    @PreAuthorize("@ss.hasPermi('source:baseInfo:add')")
    @Log(title = "线索基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SourceBaseInfo sourceBaseInfo)
    {
        return toAjax(sourceBaseInfoService.insertSourceBaseInfo(sourceBaseInfo));
    }

    /**
     * 修改线索基本信息
     */
    @PreAuthorize("@ss.hasPermi('source:baseInfo:edit')")
    @Log(title = "线索基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SourceBaseInfo sourceBaseInfo)
    {
        return toAjax(sourceBaseInfoService.updateSourceBaseInfo(sourceBaseInfo));
    }

    /**
     * 删除线索基本信息
     */
    @PreAuthorize("@ss.hasPermi('source:baseInfo:remove')")
    @Log(title = "线索基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sourceBaseInfoService.deleteSourceBaseInfoByIds(ids));
    }
}
